package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 分别使用无参和有参构造器实例化Student
 */
public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls=Class.forName("reflect.Student");
        //为参
        Object obj=cls.newInstance();
        System.out.println(obj);
        //有参
        Constructor cn= cls.getConstructor(String.class,int.class,char.class);
        Object objj=cn.newInstance("蔡徐坤",20,'女');
        System.out.println(objj);

    }
}
